package com.liuzihao.cloudLzhPayment.controller;

import com.liuzihao.cloudLzhPayment.pojo.CommentResult;
import com.liuzihao.cloudLzhPayment.pojo.Payment;
import com.liuzihao.cloudLzhPayment.service.PaymentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: Liuzihao
 * @Description: 支付控制器
 * @Date Created in 2021-09-21 00:18
 * @Modified By:
 */
@RestController
@RequestMapping("payment")
public class PaymentController {
    @Resource
    PaymentService payMentService;

    @GetMapping("getPaymentById/{id}")
    CommentResult<Payment> getPaymentById(@PathVariable("id") Long id){
        Payment payment = payMentService.getPaymentById(id);
        return payment==null?new CommentResult<>(500,"没有找到支付信息",null):new CommentResult<>(200,"响应成功",payment);
    }
    @GetMapping("getPaymentById2/{id}")
    CommentResult<Payment> getPaymentById2(@PathVariable("id") Long id){
        Payment payment = new Payment(432524l,"刘子豪");
        return payment==null?new CommentResult<>(500,"没有找到支付信息",null):new CommentResult<>(200,"响应成功",payment);
    }

    @PostMapping("savePayment")
    CommentResult savePayment(@RequestBody Payment payment){
        int i = payMentService.savePayment(payment);
        return i > 0 ? new CommentResult(200,"添加支付信息成功",null):new CommentResult(500,"添加支付信息失败",null);
    }
}
